﻿<%@ WebHandler Language="C#" Class="video" %>
using System;
using System.Web;
public class video : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        string ret = "";    //ret=-1  用户名不存在。0:设备不在线
        string sn = context.Request.QueryString["sn"].ToString();

        string lpManagerHostIpV4="", wManagerHostPort="", lpDVRIpV4="", wDVRPort="";
        NVR.BLL.DeviceInfo dev = new NVR.BLL.DeviceInfo();
        NVR.BLL.NVRDevInfo nvr = new NVR.BLL.NVRDevInfo();

        NVR.Entity.DeviceInfo devInfo = new NVR.Entity.DeviceInfo();
        NVR.Entity.NVRDeviceInfo nvrInfo = new NVR.Entity.NVRDeviceInfo();
        devInfo=dev.GetDeviceInfo(sn);
        nvrInfo = nvr.GetNVRInfoBySn(sn);
        if (nvrInfo == null)
        {
            ret = "-1";
        }
        else if (devInfo.DeviceStatus == 2)
        {
            ret = "0";
        }
        else
        {
            string Remote_Host = context.Request.ServerVariables["Remote_Host"].ToString();
            if (devInfo.IsCenterPreveiw == 1)
            {
                lpManagerHostIpV4 = context.Request.ServerVariables["SERVER_NAME"].ToString();
                wManagerHostPort = System.Configuration.ConfigurationManager.AppSettings["wManagerHostPort"].ToString();
                System.Net.IPAddress[] IPs = System.Net.Dns.GetHostAddresses(lpManagerHostIpV4);
                if (IPs.Length > 0)
                {
                    lpManagerHostIpV4 = IPs[0].ToString();
                }
                if (devInfo.STSServeIsUse== 1)
                {
                    lpManagerHostIpV4 = devInfo.STSServerIP;
                    wManagerHostPort = devInfo.STSServerPort;
                }
            }
            else
            {
                if (devInfo.RemoteIPv4 == Remote_Host)
                {
                    lpDVRIpV4 = devInfo.LocalIpv4;
                    wDVRPort = devInfo.RemotePort;
                }
                else
                {
                    lpDVRIpV4 = devInfo.RemoteIPv4;
                    wDVRPort = devInfo.RemotePort;
                }
                lpDVRIpV4 = devInfo.RemoteIPv4;
                wDVRPort = devInfo.RemotePort;
            }
            ret="video.htm?lpUserName=" + nvrInfo.deviceAdmin + "&lpPassword=" + nvrInfo.devicePwd + "&lpDVRIpV4=" + lpDVRIpV4 + "&lpManagerHostIpV4=" + lpManagerHostIpV4 + "&wDVRPort=" + wDVRPort + "&wManagerHostPort=" + wManagerHostPort + "&szSerialNo=" + sn;
        }
        context.Response.ContentType = "text/plain";
        context.Response.Write(ret);
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
}